package com.lianzai.wxapp.global;

import com.lianzai.ticket.model.TicketInstance;
import org.apache.commons.lang.StringUtils;

import java.util.concurrent.ConcurrentHashMap;

public class TicketMap {

    private static ConcurrentHashMap<String, TicketInstance> ticketMap;
    private static Integer tokenMapMutex = 1;

    static {
        ticketMap = new ConcurrentHashMap<String, TicketInstance>();
    }

    public static boolean addTicket(TicketInstance ticket) {
        if (ticket == null || ticket.getMerchantId() == null || StringUtils.isBlank(ticket.getTicketToken())) {
            return false;
        }

        ticketMap.put(ticket.getTicketToken(), ticket);

        return true;
    }

    public static TicketInstance getTicket(String token) {
        return ticketMap.get(token);
    }

    public static void removeTicket(String token) {
        ticketMap.remove(token);
    }
}
